package com.bwf.udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/5/26 10:36
 * @Copyright 博为峰
 */
public class UDPSendDemo {
    public static void main(String[] args) throws Exception {
        /*
          创建UDP传输发送端
          1.创建udp的socket服务对象
          2.创建DatagramPacket数据报包对象，封装要发送的数据，同时指定ip和端口
          3.发送数据包
          4.关闭socket服务
         */
        DatagramSocket ds = new DatagramSocket(6666);
        byte[] bytes = "张三".getBytes();
        DatagramPacket packet = new DatagramPacket(bytes, bytes.length, InetAddress.getByName("172.20.255.74"), 9999);
        ds.send(packet);
        ds.close();
    }
}
